/*
 * @Author: Robin
 * @Date: 2020-12-28 16:49:37
 * @LastEditors: Robin
 * @LastEditTime: 2020-12-28 17:53:53
 * @Description: Description
 */
package main

import (
	"fmt"
	"html/template"
	"log"
	"strings"
)

type Test struct {
	Name string
	Age  int
}

func main() {
	test := make(map[string]string, 0)
	test["name"] = "Robin"
	test["age"] = "32"
	test["name1"] = "haha"
	test["age1"] = "22"
	// Test1 = append(Test1, Test{Name: "Robin", Age: 31}, Test{Name: "hello", Age: 1})
	tmpl, err := template.ParseFiles("index.html")
	// tmpl, err := template.New("test").Parse("hello, {{.}}, {{.name}}") //建立一个模板，内容是"hello, {{.}}"
	if err != nil {
		log.Fatalln(err)
	}
	w := strings.Builder{}
	// buf := bytes.NewBuffer([]byte{})
	// buf.
	err = tmpl.Execute(&w, &test) //将string与模板合成，变量name的内容会替换掉{{.}}
	fmt.Println(w.String())
}
